<?php
namespace App\Models\Trade\Common;

use App\Models\Model;

class FishClassifyModel extends Model
{

    const TABLENAME = 'tw_trade_fish_classify';

    const STATUS_DEFAULT = 0;

    const STATUS_REMOVE = 1;
    
    private static $field = ['id', 'name', 'img'];

    /**
     * 查询一条数据
     *
     * @param int $id
     * @param array $fields
     * @return \Illuminate\Support\Collection
     */
    public static function findById($id, array $fields = [])
    {
        $query = self::dbTable();
        if (count($fields)) {
            $query->select($fields);
        }

        return $query->where('id', $id)->get();
    }

    /**
     * 查询列表（父 ID）
     *
     * @param int $parentId
     * @return \Illuminate\Support\Collection
     */
    public static function selectByParentId($parentId = 1)
    {
        $where[] = ['parent_id', $parentId];
        $where[] = ['status', self::STATUS_DEFAULT];
        return self::dbTable()
            ->select(self::$field)
            ->where($where)
            ->orderBy('sort')
            ->get();
    }
}
